package com.leo.slice;

import com.leo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        findComponentById(ResourceTable.Id_ShadowLayout_shadow).setClickedListener(this);
        findComponentById(ResourceTable.Id_ShadowLayout_shape).setClickedListener(this);
        findComponentById(ResourceTable.Id_ShadowLayout_wiki).setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        Intent intent = new Intent();
        Intent.OperationBuilder builder = new Intent.OperationBuilder()
                .withBundleName("com.leo.shadowlayout");
        switch (component.getId()) {
            case ResourceTable.Id_ShadowLayout_shadow:
                builder.withAbilityName("com.leo.ShadowAbility");
                break;
            case ResourceTable.Id_ShadowLayout_shape:
                builder.withAbilityName("com.leo.ShapeAbility");
                break;
            case ResourceTable.Id_ShadowLayout_wiki:
                builder.withAbilityName("com.leo.WikiAbility");
                break;
        }
        intent.setOperation(builder.build());
        startAbility(intent);
    }
}
